// File GenericPersonStates.cpp
//
// Purpose: Contains the states for the player
//
// Author : Bryson King (edited)
// Original Code Provided by: Mat Buckland 2002 (fup@ai-junkie.com)
// Date : 18 March 2013
// --------------------------------------------------------------
#include "GenericPersonStates.h"
#include "AbstractState.h"
#include "GenericPerson.h"
#include "Telegram.h"
#include "MessageDispatcher.h"
#include "MessageTypes.h"
#include "Time/CrudeTimer.h"
#include "EntityNames.h"

#include <iostream>
using std::cout;
using std::endl;

//------------------------------------------------------------------------methods for AttackPlayer
AttackPlayer* AttackPlayer::Instance()
{
	static AttackPlayer instance;
	return &instance;
}

void AttackPlayer::Enter(CGenericPerson* pPerson)
{
	#ifdef DEBUG_SECTION
		// Output status of the generic person
		cout << endl << GetNameOfEntity(pPerson->ID()) << ": " << "Entering the Attack state";
		cout << endl << GetNameOfEntity(pPerson->ID()) << ": " << "Health is currently at " << 
			pPerson->Health();
	#endif
}

void AttackPlayer::Execute(CGenericPerson* pPerson)
{
	//if generic person's health drops to 0 or less, die
	if (pPerson->Health() <= 0)
	{
		pPerson->GetFSM()->ChangeState(DeadGenericPlayer::Instance());
	}

	//if health not an issue, attack enemies in range
	//ALL ENEMIES IN SAME SPACE ARE IN RANGE
	
	//if no enemies in range, proceed toward the bridge
	if (true)
	{
		pPerson->GetFSM()->ChangeState(Standby::Instance());
	}
}

void AttackPlayer::Exit(CGenericPerson* pPerson)
{
	#ifdef DEBUG_SECTION
		// Output status of the terrorist
		cout << endl << GetNameOfEntity(pPerson->ID()) << ": " << "Exiting the Attack state";
		cout << endl << GetNameOfEntity(pPerson->ID()) << ": " << "Health is currently at " << 
			pPerson->Health();
	#endif
}

bool AttackPlayer::OnMessage(CGenericPerson* agent, const Telegram& msg)
{
	//send msg to global message handler
	return false;
}

//------------------------------------------------------------------------methods for Standby

Standby* Standby::Instance()
{
	static Standby instance;
	return &instance;
}

void Standby::Enter(CGenericPerson* pPerson)
{  
	#ifdef DEBUG_SECTION
		// Output status of the terrorist
		cout << endl << GetNameOfEntity(pPerson->ID()) << ": " << "Entering the Standby state";
		cout << endl << GetNameOfEntity(pPerson->ID()) << ": " << "Health is currently at " << 
			pPerson->Health();
	#endif
}

void Standby::Execute(CGenericPerson* pPerson)
{
	//if attacked, enter Attack state
	if (/*attacked*/true)
	{
		pPerson->GetFSM()->ChangeState(AttackPlayer::Instance());
	}
	//if not attacked, maintain current state
}

void Standby::Exit(CGenericPerson* pPerson)
{
	#ifdef DEBUG_SECTION
		// Output status of the terrorist
		cout << endl << GetNameOfEntity(pPerson->ID()) << ": " << "Exiting the Standby state";
		cout << endl << GetNameOfEntity(pPerson->ID()) << ": " << "Health is currently at " << 
			pPerson->Health();
	#endif
}

bool Standby::OnMessage(CGenericPerson* agent, const Telegram& msg)
{
	//send msg to global message handler
	return false;
}
//------------------------------------------------------------------------methods for DeadGenericPlayer

DeadGenericPlayer* DeadGenericPlayer::Instance()
{
	static DeadGenericPlayer instance;
	return &instance;
}

void DeadGenericPlayer::Enter(CGenericPerson* pPerson)
{
	#ifdef DEBUG_SECTION
		// Output status of the terrorist
		cout << endl << GetNameOfEntity(pPerson->ID()) << ": " << "Entering the Dead state";
		cout << endl << GetNameOfEntity(pPerson->ID()) << ": " << "Health is currently at " << 
			pPerson->Health();
	#endif
}

void DeadGenericPlayer::Execute(CGenericPerson* pPerson)
{
	//if dead, stay dead until entity removed from game memory
}

void DeadGenericPlayer::Exit(CGenericPerson* pPerson)
{ 
	#ifdef DEBUG_SECTION
		// Output status of the terrorist
		cout << endl << GetNameOfEntity(pPerson->ID()) << ": " << "Exiting the Dead state";
		cout << endl << GetNameOfEntity(pPerson->ID()) << ": " << "Health is currently at " << 
			pPerson->Health();
	#endif
}


bool DeadGenericPlayer::OnMessage(CGenericPerson* agent, const Telegram& msg)
{
	//send msg to global message handler
	return false;
}
